package com.handpay.zztong.hp.bean;
import com.handpay.zztong.hp.log.HPLog;
import com.handpay.zztong.hp.main.model.ratelist.RateListBean;
import java.io.Serializable;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;

public class Rate implements Serializable {

    public static final int INVALID_ISPUBLICCHAREGE_ID = -1;
    private int mRateCode;
    private String mRateName = null;
    private int mIsPublicCharge = INVALID_ISPUBLICCHAREGE_ID;
    private String isDefault = null;
    private String rateAmount=null;
    public String getIsDefault() {
        return isDefault;
    }

    public void setIsDefault(String isDefault) {
        this.isDefault = isDefault;
    }

    public int getRateCodeId() {
        return mRateCode;
    }

    public void setRateCodeId(int rateCode) {
        this.mRateCode = rateCode;
    }

    public String getRateName() {
        return mRateName;
    }

    public void setRateName(String rateName) {
        this.mRateName = rateName;
    }

    public int getIsPublicChargeId() {
        return mIsPublicCharge;
    }

    public void setIsPublicChargeId(int isPublicCharge) {
        this.mIsPublicCharge = isPublicCharge;
    }

    public boolean isSelectDefault() {
        return isDefault != null && "1".equals(isDefault);
    }


    public String getRateAmount() {
        return rateAmount;
    }

    public void setRateAmount(String rateAmount) {
        this.rateAmount = rateAmount;
    }

    public static Rate generateRate(RateListBean.ListBean data) {
        Rate r = new Rate();
        try {
            r.setRateCodeId(Integer.parseInt(new DecimalFormat("0").format(Double.parseDouble(data.getRateCode()))));
            r.setRateName(data.getRateName());
            r.setIsPublicChargeId(Integer.parseInt(new DecimalFormat("0").format(Double.parseDouble(data.getIsPublicCharge()))));
            r.setRateAmount(data.getRateAmount());
            if (data.getIsDefault() != null) {
                r.setIsDefault(data.getIsDefault());
            }
            return r;
        } catch (Exception e) {
            return null;
        }
    }


    @Override
    public String toString() {
        return "Rate{" +
                "mRateCode=" + mRateCode +
                ", mRateName='" + mRateName + '\'' +
                ", mIsPublicCharge=" + mIsPublicCharge +
                ", isDefault='" + isDefault + '\'' +
                ", rateAmount='" + rateAmount + '\'' +
                '}';
    }

    public static ArrayList<Rate> generateListRates(List<RateListBean.ListBean> dataList) {
        ArrayList<Rate> rateBills = new ArrayList<Rate>();
        for (RateListBean.ListBean billData : dataList) {
            Rate r = generateRate(billData);
            if (null != r) {
                rateBills.add(r);
            }
        }
        HPLog.i(HPLog.TAG_RESULT,"--generateListRates--rateBills.size:"+rateBills.size());
        return rateBills;
    }

}